package com.my.controller;


import com.my.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@CrossOrigin("*")
@RequestMapping("/orders")
public class OrdersController {

    OrdersService ordersService;

    @Autowired
    public void setOrdersService(OrdersService ordersService) {
        this.ordersService = ordersService;
    }

    @RequestMapping("/send")
    public String sendOrders(Integer ordersId, HttpServletRequest req) {
        return this.ordersService.sendOrders(ordersId, req);
    }

    @RequestMapping("/delete")
    public String deleteOrders(Integer ordersId, HttpServletRequest req) {
        return this.ordersService.deleteOrders(ordersId, req);
    }

    @RequestMapping("/addOrdersLogistics")
    String addOrdersLogistics(Integer ordersId, String logistics, HttpServletRequest req) {
        return this.ordersService.addOrdersLogistics(ordersId, logistics, req);
    }

    @RequestMapping("/showForBusiness")
    public String showAll(String context,
                          Integer currentPage,
                          Integer pageSize,
                          String sort,
                          Boolean asc,
                          HttpServletRequest req) {
        return this.ordersService.showAll(context, currentPage, pageSize, sort, asc, req);
    }

    @RequestMapping("/showForUser")
    public String showAllForUser(String context,
                                 Integer currentPage,
                                 Integer pageSize,
                                 String sort,
                                 Boolean asc,
                                 HttpServletRequest req) {
        return this.ordersService.showAllForUser(context, currentPage, pageSize, sort, asc, req);
    }

    @RequestMapping("/showOne")
    public String showOrderForUser(Integer ordersId, HttpServletRequest req) {
        return this.ordersService.showOrderForUser(ordersId, req);
    }

    @RequestMapping("/add")
    public String addOrders(Integer goodsNum, Integer goodsId, HttpServletRequest req) {
        return this.ordersService.addOrders(goodsNum, goodsId, req);
    }

    @RequestMapping("/addAddress")
    public String addAddress(Integer ordersId, Integer addressId, HttpServletRequest req) {
        return this.ordersService.addAddress(ordersId, addressId, req);
    }

    @RequestMapping("/confirm")
    public String confirmGet(Integer ordersId, HttpServletRequest req) {
        return this.ordersService.confirmGet(ordersId, req);
    }
}
